<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>任务列表</title>
    <div th:include="layout/resources :: resources"></div>
</head>
<body>
<div class="container-fluid">
    <div id="toolbar">
        <select id="startTimeLevel" onchange="refresh();">
            <option value="1">今日任务</option>
            <option value="0">所有</option>
        </select>
    </div>
    <table id="taskDetail"></table>
</div>
</body>
<script type="text/javascript">
    $("#taskDetail").framework().bootstrapTable({
        url: "/taskDetail/getListByPage",
        queryParams: function (params) {
            params.startTimeLevel = $("#startTimeLevel").val();
            return params;
        },
        columns: [
            {
                field: '',
                title: '序号',
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            }, {
                field: 'finished',
                title: '操作',
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    if (value) {
                        var resultStr = '<a href="javascript:deleteOne(\'' + row.id + '\');">删除</a>&nbsp;&nbsp;';
                        resultStr += '<a href="javascript:recover(\'' + row.id + '\');">恢复</a>';
                        return resultStr;
                    } else {
                        return '<a href="javascript:stop(\'' + row.id + '\');">暂停</a>';
                    }
                }
            }, {
                field: 'funName',
                title: '項目',
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return '<a href="javascript:showDetail(\'' + row.id + '\',' + row.fun + ')">' + value + '</a>';
                }
            }, {
                field: 'taskNo',
                title: '任务编号',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'id',
                title: '任务ID',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'groupNames',
                title: '执行组',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'totalTime',
                title: '执行次数',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'finishTime',
                title: '实际完成次数',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'startTime',
                title: '开始时间',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'endTime',
                title: '结束时间',
                align: 'center',
                valign: 'middle'
            }, {
                field: 'createDate',
                title: '创建时间',
                align: 'center',
                valign: 'middle'
            }]
    })

    function stop(id, fun) {
        layer.confirm('确认停止吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                method: "get",
                url: createUrl("/taskDetail/stopTask"),
                data: {id: id, fun: fun},
                success: function (result) {
                    if (result.success) {
                        refresh();
                        framework.alert("任务已停止");
                    }
                }
            })
        }, function () {
            layer.closeAll();
        });
    }

    function deleteOne(id) {
        layer.confirm('确认删除吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                method: "get",
                url: createUrl("/taskDetail/delete?id=" + id),
                success: function (result) {
                    if (result.success) {
                        refresh();
                        framework.alert("任务已删除");
                    }
                }
            })
        }, function () {
            layer.closeAll();
        });
    }

    function refresh() {
        $('#taskDetail').bootstrapTable('refresh');
    }

    function showDetail(id, fun) {
        framework.openWindow('/taskDetail/toDetail/' + id + "/" + fun, "70%", "70%", "任务详情");
    }

    function recover(id) {
        layer.confirm('确认恢复吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                method: "get",
                url: createUrl("/taskDetail/recover/" + id + "/false"),
                success: function (result) {
                    if (result.success) {
                        refresh();
                        framework.alert("任务已恢复");
                    }
                }
            })
        }, function () {
            layer.closeAll();
        });
    }
</script>
</html>
